/*************************************************************************************
*Copyright (c) 2011, Intel Mobile Communications GmbH. 
*All rights reserved.
*
*Redistribution and use in source and binary forms, with or without
*modification, are permitted provided that the following conditions are met:
*    * Redistributions of source code must retain the above copyright
*      notice, this list of conditions and the following disclaimer.
*    * Redistributions in binary form must reproduce the above copyright
*      notice, this list of conditions and the following disclaimer in the
*      documentation and/or other materials provided with the distribution.
*    * Neither the name of the <organization> nor the
*      names of its contributors may be used to endorse or promote products
*      derived from this software without specific prior written permission.
*
*THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
*ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
*WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
*DISCLAIMED. IN NO EVENT SHALL INTEL MOBILE COMMUNICATIONS GMBH. BE LIABLE FOR ANY
*DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
*(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
*LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
*ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
*(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
*SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*************************************************************************************/



#include "cef_domain.h"
using namespace std;
cef_operating_point::cef_operating_point()
{
	id=0;
	name="";
	frequency=0;
	voltage=0;
}
cef_operating_point::cef_operating_point(unsigned i,string n,double f,double v)
{
	id=i;
	name=n;
	frequency=f;
	voltage=v;
}
cef_operating_point::~cef_operating_point()
{
}
	//Setters
void cef_operating_point::setID(unsigned i)
{
	id=i;
}

void cef_operating_point::setName(string n)
{
	name=n;	
}
void cef_operating_point::setFrequency(double f)
{
	frequency=f;
}
void cef_operating_point::setVoltage(double v)
{
	voltage=v;
}
//Getters
unsigned cef_operating_point::getID()
{
	return id;
}
string cef_operating_point::getName()
{
	return name;
}
double cef_operating_point::getFrequency()
{
	return frequency;
}
double cef_operating_point::getVoltage()
{
	return voltage;
}
#ifdef _DEBUG
void cef_operating_point::print()
{
	cout<<"CEF Operating Point\nBEGIN\n";
	cout<<"ID: "<<id<<" Name: "<<name<<" Freq.: "<<frequency<<" Voltage: "<<voltage<<endl; 
	cout<<"END\n";
}
#endif
cef_domain::cef_domain()
{
	id=0;
	name="default";
	clock_id=0;
	power_network_id=0;
	operating_points=NULL;
}
cef_domain::cef_domain(unsigned i, string n, unsigned clk,unsigned pow, vector<cef_operating_point* >* oppt):id(i),name(n),clock_id(clk),power_network_id(pow)
{
	operating_points=oppt;	
}
cef_domain::~cef_domain()
{
	if(operating_points)
	{
		for(unsigned i=0;i<operating_points->size();i++)
		{
			delete (*operating_points)[i];	
		}
		delete operating_points;
	}	
}
//Setters
void cef_domain::setName(string n)
{
	name=n;
}
void cef_domain::setID(unsigned i)
{
	id=i;	
}
void cef_domain::setClockID(unsigned c)
{
	clock_id=c;	
}
void cef_domain::setPowerID(unsigned p)
{
	power_network_id=p;
}
void cef_domain::setOpPts(vector<cef_operating_point* >* oppts)
{
	operating_points=oppts;
}
void cef_domain::addOpPt(cef_operating_point* pt)
{
	if(operating_points==NULL) operating_points=new vector<cef_operating_point* >(); 
	operating_points->push_back(pt);
}
//Getters
string cef_domain::getName()
{
	return name;
}
unsigned cef_domain::getID()
{
	return id;
}
unsigned cef_domain::getClockID()
{
	return clock_id;
}
unsigned cef_domain::getPowerID()
{
	return power_network_id;
}

vector<cef_operating_point* >* cef_domain::getOpPts()
{
	return operating_points;
}
cef_operating_point* cef_domain::getOpPt(unsigned i)
{
	if(operating_points) return (*operating_points)[i];
	return NULL;
}

#ifdef _DEBUG
void cef_domain::print()
{

	cout<<"CEF Domain\nBEGIN\n";
	cout<<"Name: "<<name<<" ID: "<<id<<" ClockID: "<<clock_id<<" PowerID: "<<power_network_id<<endl;
	if(operating_points){
		cout<<"Operating Points:\n";
		for(unsigned i=0;i<operating_points->size();i++)
		{
			(*operating_points)[i]->print();
		}
	}
	cout<<"END\n";
}
#endif
